//
//  ChoiceView.swift
//  2048Demo
//
//  Created by Windy on 2024/4/14.
//  Copyright © 2024 wpsd. All rights reserved.
//

import UIKit

class ChoiceView: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let boardWH = SCREEN_WIDTH - boardLeftMargin * 2
        let gameBoard = GameBoard(frame: CGRect(x: 0, y: 0, width: boardWH, height: boardWH))
            gameBoard.center = view.center
        var cellWH = (gameBoard.frame.width - margin * CGFloat(cellRowCount + 1)) / CGFloat(cellRowCount)
        var scoreW = cellWH * 3
        var scoreH = cellWH * 0.9
        setupButton1()
        setupButton2()        // 创建背景图片视图并设置图片
           let backgroundImageView = UIImageView(frame: view.bounds)
           backgroundImageView.image = UIImage(named: "2")
           backgroundImageView.contentMode = .scaleToFill // 或者选择其他适合的模式
        
        // 将背景图片视图插入到视图层次的底部，确保它不会盖其他视图，如按钮等
           view.insertSubview(backgroundImageView, at: 0)
        
        
    }
    
    private func setupButton1() {
        
        let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 70))
        btn.setTitleColor(UIColor.black, for: .normal)
        btn.setTitle("Classic  Mode", for: .normal)
        btn.setTitleColor(UIColor(red: 1.0, green: 0.55, blue: 0.0, alpha: 1.0), for: .normal)  // 设置深橙色文字
           btn.titleLabel?.font = UIFont(name: "Marker Felt", size: 32)
        btn.center = CGPoint(x: view.center.x, y: view.center.y-200)
        btn.addTarget(self, action: #selector(btnClick1(sender:)), for: .touchUpInside)
        view.addSubview(btn)
        
    }
        private func setupButton2() {
            
            let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 300, height: 70))
            btn.setTitleColor(UIColor.black, for: .normal)
            btn.setTitle("Challenge  Mode", for: .normal)
            btn.setTitleColor(UIColor(red: 1.0, green: 0.55, blue: 0.0, alpha: 1.0), for: .normal)  // 设置深橙色文字
               btn.titleLabel?.font = UIFont(name: "Marker Felt", size: 32)
            btn.center = CGPoint(x: view.center.x, y: view.center.y)
            btn.addTarget(self, action: #selector(btnClick2(sender:)), for: .touchUpInside)
            view.addSubview(btn)
            
        }
        
    @objc private func btnClick2(sender: UIButton) {
            
            present(SwitchView(), animated: true, completion: nil)
            
        }

    
    @objc private func btnClick1(sender: UIButton) {
        
        present(SwitchView1(), animated: true, completion: nil)
        
    }

}
